package org.monkey.config.client.controller;

import org.monkey.config.client.response.JsonResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.Map;

@RestController
@RequestMapping("/clientInfo")
@RefreshScope // 需要刷新的配置  类需要添加注解
public class ClientInfoController {

  private static final Logger logger = LoggerFactory.getLogger(ClientInfoController.class);

  @Value("${spring.cloud.config.uri}")
  private static String serverUri;

  @Value("${panda.client.version}")
  private String version;

  @Value("${panda.client.hello}")
  private String helloInfo;

  @PostConstruct
  void init() {
    logger.info("server  uri : " + helloInfo);
  }

  @RequestMapping("/querySystemInfo")
  public JsonResponse<Map<String, Object>> querySystemInfo(Map<String, Object> param) {

    param.put("version", version);
    param.put("helloInfo", helloInfo);
    return JsonResponse.success("query info success", param);
  }
}
